<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.cyys.com/cyystaglib" prefix="cyys"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<title>${SYSTEM_NAME}</title>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuiadmin/layui/css/layui.css?v=${FILE_VERSION}" media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuiadmin/style/admin.css?v=${FILE_VERSION}" media="all">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/static/js/simpleCalendar/css/simple-calendar.css?v=${FILE_VERSION}">
</head>
<body>
<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-card-header">节假日管理</div>
			<div class="layui-card-body" style="height: 600px">
				<div class="layui-form layer-query" >
				    <div class="layui-inline">
				      <button class="layui-btn" onclick="initData(false)">初始化周末数据</button>
				     </div>
				</div>
			    <hr class="layui-bg-green">
				<div id="calendar" ></div>
			</div>
	</div>
</div>
	
	<script src="${pageContext.request.contextPath}/static/js/common-2.0.0.js?v=${FILE_VERSION}"></script>
	<script src="${pageContext.request.contextPath}/static/layuiadmin/layui/layui.js?v=${FILE_VERSION}"></script>
	<script src="${pageContext.request.contextPath}/static/js/jquery-3.3.1.min.js?v=${FILE_VERSION}"></script>
	<script src="${pageContext.request.contextPath}/static/js/simpleCalendar/simple-calendar.js?v=${FILE_VERSION}"></script>
	<script>
		var layer;
		layui.config({
			base: getContextPath() + '/static/layuiadmin/' //静态资源所在路径
		}).extend({
			index: 'lib/index' //主入口模块
		}).use(['element','layer'], function() {
			var element = layui.element;
			layer = layui.layer;
			initData(true);
		});
		
		function addReload(title) {
			$(".sc-selected").addClass("sc-mark");
			$(".sc-selected").attr("title",title);
		}

		function deleteById(date,obj) {
			layer.confirm('确认要取消节假日吗？', function(index) {
				$ajax({
					url: "/sys/paramHoliday/del/deleteByDate",
					data: {
						date : date
		            },
			        succCallback: function (json) {
			        	if (json.success == true) {
							obj.removeClass("sc-mark");
							obj.removeAttr("title");
						}
			        }
				});
			});
		}
		
		function addLayer(year,month,day,date) {
			var url = getContextPath() + '/sys/paramHoliday/add/input?holidayYear=' + year 
					+ "&holidayMonth=" + month
					+ "&holidayDay=" + day
					+ "&holidayDate=" + date;
			layer.open({
				title : "添加节假日",
				type : 2,
				area : [ '400px', '240px' ],
				anim : 2,
				content : [ url, 'no' ]
			});
		}

		function modi() {
			var checkStatus = table.checkStatus('tableList'), data = checkStatus.data;
			if (data.length == 0 || data.length > 1) {
				layer.msg("请选择一条数据");
				return false;
			}
			addLayer(data[0].id);
		}
		
		function initData(flag){
			if(!flag){
				layer.confirm('初始化数据会清空已经生成的节假日数据，您确定初始化吗？', function(index) {
					$ajax({
						url: "/sys/paramHoliday/add/createHolidayForYear",
				        succCallback: function (json) {
				        	if (json.success == true) {
				        		createDate(flag);
							}
				        }
					});
				});
			}else{
				createDate(flag);
			}
		}
		
		function createDate(flag){
			$ajax({
				url: "/sys/paramHoliday/list/listInfo",
		        isShowLayer : false,
		        succCallback: function (json) {
		        	var year = json.data.year;
			    	var datamark = eval("(" + json.data.mark + ")");
			    	var options = {
		    			width : '1100px',
		    			height : '500px',
		    			language : 'CH', //语言
		    			showLunarCalendar : false, //阴历
		    			showHoliday : false, //休假
		    			showFestival : false, //节日
		    			showLunarFestival : false, //农历节日
		    			showSolarTerm : false, //节气
		    			showMark : true, //标记
		    			showYearControll : false,
		    			timeRange : {
		    				startYear : year,
		    				endYear : year
		    			},
		    			mark : datamark,
		    			theme : {
		    				changeAble : false,
		    				weeks : {
		    					backgroundColor : '#FBEC9C',
		    					fontColor : '#4A4A4A',
		    					fontSize : '20px',
		    				},
		    				days : {
		    					backgroundColor : '#ffffff',
		    					fontColor : '#565555',
		    					fontSize : '24px'
		    				},
		    				todaycolor : 'orange',
		    				activeSelectColor : 'orange',
		    			}
		    		}
			    	if(flag)
			    		new SimpleCalendar('#calendar',options);
			    	else{
			    		$("#calendar").empty();
			    		new SimpleCalendar('#calendar',options);
			    	}
			    	
			    	$(".item-nolunar").click(function() { //天数格添加点击事件。
				        var year = $(".sc-select-year").val(); //获取当前选择年份。
				        var month = $(".sc-select-month").val(); //获取当前选择月份。
				        var day = $(this).children(".day").html(); //获取当前选择天数。
				        var date = year + "-" + month + "-" + day;
				        var mark = $(this).hasClass("sc-mark"); //获取当前选择月份。
				        if(mark){
				        	deleteById(date,$(this));
				        }else{
				        	addLayer(year,month,day,date);
				        }
				    });
		        }
			});
		}
	</script>
</body>
</html>